package com.dmxh.controller;

import com.dmxh.params.QueryParams;
import com.dmxh.pojo.TbGoods;
import com.dmxh.result.PageList;
import com.dmxh.result.Result;
import com.dmxh.service.GoodsService;
import com.dmxh.vo.GoodsVo;
import com.dmxh.vo.ItemVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("/goods")
public class GoodsController {

    @Autowired
    private GoodsService goodsService;

    @PostMapping("/addInfo")
    public Result addInfo(@RequestBody GoodsVo goodsVo, HttpServletRequest request) {
        String username = request.getHeader("username");
        goodsVo.setSellerId(username);
        goodsService.addInfo(goodsVo);
        return Result.ok();
    }

    @PostMapping("/queryPageBySeller")
    public Result<PageList<GoodsVo>> queryPage(@RequestBody QueryParams queryParams) {
        PageList<GoodsVo> pageList = goodsService.queryPageBySeller(queryParams);
        return Result.ok().setData(pageList);
    }

    @PostMapping("/updateInfo")
    public Result updateInfo(@RequestBody GoodsVo goodsVo) {
        goodsService.updateInfo(goodsVo);
        return Result.ok();
    }

    @PostMapping("/queryPageByAdmin")
    public Result queryPageByAdmin(@RequestBody QueryParams queryParams) {
        PageList<GoodsVo> pageList = goodsService.queryPageByAdmin(queryParams);
        return Result.ok().setData(pageList);
    }

    @PostMapping("/updateStatus")
    public Result updateStatus(@RequestBody GoodsVo goodsVo) {
        goodsService.updateStatus(goodsVo);
        return Result.ok();
    }

    @GetMapping("/getById/{id}")
    public Result getById(@PathVariable("id")long id) {
        GoodsVo goodsVo = goodsService.getById(id);
        return Result.ok().setData(goodsVo);
    }




}
